home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / REMLINE.BAS (.txt) < prev    next >
QuickBASIC Tokenized Source  |  1988-09-08  |  12KB  |  210 lines

  1. GetToken
  2. Search
  3. Delim
  4. StrSpn
  5. InString
  6.     Separator
  7. StrBrk
  8. IsDigit
  9. Char%
  10. GetFileNames
  11. BuildTable
  12. GenOutFile
  13. InitKeyTable
  14. TRUE:
  15. falseG
  16. MaxLines
  17.     LineTable
  18.     LineCount
  19. Seps,
  20.     InputFile
  21. OutputFile
  22. TmpFile
  23. KeyWordCount
  24. KeyWordTable
  25. KeyData
  26. FileErr1
  27. FileErr2
  28. InLin
  29. token
  30. KeyIndex
  31. LineNumber
  32. FoundNumber
  33. index
  34. BegPos
  35. SaveStr
  36. NewPos
  37. Count
  38. KeyWord
  39. CharAsc
  40.    Microsoft RemLine - Line Number Removal Utility
  41.    Copyright (C) Microsoft Corporation   - 1985, 1986, 1987
  42.    REMLINE.BAS is a program to remove line numbers from Microsoft BASIC
  43.    Programs. It removes only those line numbers that are not the object
  44.    of one of the following statements: GOSUB, RETURN, GOTO, THEN, ELSE,
  45.    RESUME, RESTORE, or RUN.s
  46.    REMLINE is run by typings
  47.  REMLINE [<input> [, <output>]]e
  48.    where <input> is the name of the file to be processed and <output>E
  49.    is the name of the file or device to receive the reformatted output.
  50.    If no extension is given, .BAS is assumed (except for output devices).
  51.    If file names are not given, REMLINE prompts for file names. If both)
  52.    file names are the same, REMLINE saves the original file with the
  53.    extension .BAK.
  54.    REMLINE makes several assumptions about the program:f
  55.  1. It must be correct syntactically, and must run in BASICA ort
  56.  GWBASIC interpreter.t
  57.  2. There is a 400 line limit. To process larger files, change
  58.  MaxLines constant.l
  59.  3. The first number encountered on a line is considered a line
  60.  number; thus some continuation lines (in a compiler specificn
  61.  constructiion) may not be handled correctly.o
  62.  4. REMLINE can handle simple statements that test the ERL function
  63.  using  relational operators such as =, <, and >. For example,
  64.  the following statement is handled correctly:
  65.  IF ERL = 100 THEN END
  66.  Line 100 is not removed from the source code. However, more
  67.  complex expressions that contain the +, -, AND, OR, XOR, EQV,
  68.  MOD, or IMP operators may not be handled correctly. For example,o
  69.  in the following statement REMLINE does not recognize line 105e
  70.  as a referenced line number and removes it from the source code:
  71.  IF ERL + 5 = 105 THEN END
  72.    If you do not like the way REMLINE formats its output, you can modify
  73.    the output lines in SUB GenOutFile. An example is shown in comments.y
  74.  Function and Subprogram declarations.
  75.  Global and constant datad
  76.  Keyword search data
  77.  THEN, ELSE, GOSUB, GOTO, RESUME, RETURN, RESTORE, RUN, ERL, ""
  78.  Start of module-level program codeE
  79.  ,:=<>()d%    
  80. Working"
  81.  . . .
  82. CON"q
  83.       Invalid file name"
  84.       New input file name (ENTER to terminate): 
  85.       Output file name (ENTER to print to screen) :"
  86. GetToken
  87.  GetToken$:
  88.   Extracts tokens from a string. A token is a word that is surroundedP
  89.   by separators, such as spaces or commas. Tokens are extracted ande
  90.   analyzed when parsing sentences or commands. To use the GetToken$e
  91.   function, pass the string to be parsed on the first call, then pass
  92.   a null string on subsequent calls until the function returns a null
  93.   to indicate that the entire string has been parsed.n
  94.  Input:d
  95.   Search$ = string to search
  96.   Delim$  = String of separators
  97.  Output:
  98.   GetToken$ = next token
  99.  Note that SaveStr$ and BegPos must be static from call to calla
  100.  (other variables are only static for efficiency).
  101.  If first call, make a copy of the stringi
  102.  Find the start of the next tokene
  103.  Set position to start of token
  104.  If no new token, quit and return null
  105.  Find end of token
  106.  Set position to end of token
  107.  If no end of token, return set to end a value
  108.  Cut token out of search string 
  109.  Set new starting position
  110. StrSpn
  111.  StrSpn:
  112.   Searches InString$ to find the first character that is not one ofn
  113.   those in Separator$. Returns the index of that character. This
  114.   function can be used to find the start of a token.
  115.  Input:i
  116.   InString$ = string to search
  117.   Separator$ = characters to search fort
  118.  Output:
  119.   StrSpn = index to first nonmatch in InString$ or 0 if all match
  120.  Look for start of a token (character that isn't a delimiter).
  121. StrBrk
  122.  StrBrk:
  123.   Searches InString$ to find the first character from among those in
  124.   Separator$. Returns the index of that character. This function can
  125.   be used to find the end of a token.a
  126.  Input:e
  127.   InString$ = string to search
  128.   Separator$ = characters to search for
  129.  Output:
  130.   StrBrk = index to first match in InString$ or 0 if none matchn
  131.  Look for end of token (first character that is a delimiter).c
  132. IsDigit
  133.  IsDigit:
  134.   Returns true if character passed is a decimal digit. Since any
  135.   BASIC token starting with a digit is a number, the function only
  136.   needs to check the first digit. Doesn't check for negative numbers,
  137.   but that's not needed here.g
  138.  Input:h
  139.   Char$ - initial character of string to check
  140.  Output:
  141.   IsDigit - true if within 0 - 9
  142. GetFileNames
  143.  GetFileNames:
  144.   Gets a file name from COMMAND$ or by prompting the user.
  145.  Input:a
  146.   Used Command$ or user inputN
  147.  Output:
  148.   Defines InputFiles$ and OutputFiles$
  149.  Microsoft RemLine: Line Number Removal Utility"
  150.        (.BAS assumed if no extension given)"
  151.       Input file name (ENTER to terminate): 
  152.       Output file name (ENTER to print to screen): "
  153.       Output file name (ENTER to print to screen): "
  154. CON";
  155. SCRN;
  156. PRN";
  157. COM1;
  158. COM2;
  159. LPT1;
  160. LPT2;
  161. LPT3;
  162. BuildTable
  163.  BuildTable:
  164.    Examines the entire text file looking for line numbers that are
  165.    the object of GOTO, GOSUB, etc. As each is found, it is entered
  166.    into a table of line numbers. The table is used during a second
  167.    pass (see GenOutFile), when all line numbers not in the listo
  168.    are removed.n
  169.  Input:r
  170.    Uses globals KeyWordTable$, KeyWordCount, and Seps$
  171.  Output:
  172.    Modefies LineTable! and LineCount
  173.  Get line and first tokend
  174.  See if token is keyword
  175.  Get possible line number after keywordo
  176.  Check each token to see if it is a line numberd
  177.  (the LOOP is necessary for the multiple numbers
  178.  of ON GOSUB or ON GOTO). A non-numeric token will
  179.  terminate search.
  180.  Get next token
  181. GenOutFile
  182.  GenOutFile:
  183.   Generates an output file with unreferenced line numbers removed.
  184.  Input:a
  185.   Uses globals LineTable!, LineCount, and Seps$n
  186.  Output:
  187.   Processed file
  188.  Speed up by eliminating comma and colon (can't separate first token)s
  189.  "d%    
  190.  Get first token and process if it is a line numbera
  191.  See if line number is in table of referenced line numbers
  192.  Modify line strings
  193.  You can replace the previous lines with your owne
  194.  code to reformat output. For example, try these lines:e
  195. TmpPos1 = StrSpn(InLin$, Sep$) + LEN(Token$)
  196. TmpPos2 = TmpPos1 + StrSpn(MID$(InLin$, TmpPos1), Sep$)e
  197. IF FoundNumber THEN 
  198.    InLin$ = LEFT$(InLin$, TmpPos1 - 1) + CHR$(9) + MID$(InLin$, TmpPos2)
  199.    InLin$ = CHR$(9) + MID$(InLin$, TmpPos2)R
  200. END IF
  201.  Print line to file or console (PRINT is faster than console device)
  202. InitKeyTable
  203.  InitKeyTable:
  204.   Initializes a keyword table. Keywords must be recognized so that
  205.   line numbers can be distinguished from numeric constants.s
  206.  Input:n
  207.   Uses KeyData
  208.  Output:
  209.   Modifies global array KeyWordTable$r
  210.